package backTrack;

import java.util.ArrayList;
import java.util.List;

public class permute {
    List<List<Integer>> list = new ArrayList<>(); 
    public List<List<Integer>> permute(int[] nums) {
        boolean[] mark = new boolean[nums.length];
        for(int i =0;i<nums.length;i++){
            mark[i]=true;
            ArrayList<Integer> subList = new ArrayList<>();
            backTrack(nums[i],subList, mark,nums,nums.length);
            mark[i]=false;
        }

        return list;
    }
    public void backTrack(int num,List<Integer> subList,boolean[] mark,int[] nums,int count){
        subList.add(num);
        if (count==1) {

            list.add(new ArrayList<>(subList));
        }
        for(int i=0;i<nums.length;i++){
            if (!mark[i]) {
                mark[i]=true;
                backTrack(nums[i],subList,mark,nums,count-1);
                mark[i]=false;
                subList.remove(subList.size()-1);
            }
        }
    }
    public static void main(String[] args) {
        permute obj= new permute();
        // int []nums = new int[]{1,2,3};
        // int []nums = new int[]{1};
        int []nums = new int[]{1,0};
        List<List<Integer>> lists = obj.permute(nums);
        for(List<Integer>list:lists){
            for(Integer i:list){
                System.out.println(i);
            }
            System.out.println("============");
        }
    }
}
